<?php


namespace app\adminapi\validate\user;


use app\common\model\user\UserType;
use app\common\validate\BaseValidate;

/**
 * @projectName src
 */
class UserTypeValidate extends BaseValidate
{
    protected $rule = [
        'id' => 'require|checkUserType',
        'type_name'=>'require|unique:'.UserType::class,
    ];

    protected $message = [
        'id.require' => '参数缺失',
        'type_name.require' => '请填写用户类型',
        'type_name.unique' => '用户类型已存在',
    ];

    /**
     * @notes 添加场景
     * sceneAdd
     */
    public function sceneAdd()
    {
        return $this->remove('id', true);
    }

    /**
     * @notes 详情场景
     * sceneAdd
     */
    public function sceneDetail()
    {
        return $this->only(['id']);
    }

    /**
     * @notes 编辑场景
     * sceneAdd
     */
    public function sceneEdit()
    {
    }

    /**
     * @notes 删除场景
     * sceneAdd
     */
    public function sceneDelete()
    {
        return $this->only(['id']);
    }

    public function checkUserType($value)
    {
        $userType = UserType::findOrEmpty($value);
        if ($userType->isEmpty()) {
            return '用户类型不存在';
        }
        return true;
    }
}